import { NextResponse } from 'next/server'
import { pool } from '@/lib/database'

/**
 * GET /api/health - 健康检查端点
 * 检查数据库连接状态，不返回实际数据
 */
export async function GET() {
    try {
        // 简单的数据库连接测试
        const result = await pool.query('SELECT 1 as health_check')

        if (!result.rows || result.rows.length === 0) {
            return NextResponse.json({
                success: false,
                status: 'unhealthy',
                error: 'Database query returned no results'
            }, { status: 500 })
        }

        return NextResponse.json({
            success: true,
            status: 'healthy',
            timestamp: new Date().toISOString(),
            database: 'PostgreSQL'
        })

    } catch (error) {
        return NextResponse.json({
            success: false,
            status: 'unhealthy',
            error: error.message
        }, { status: 500 })
    }
}